package com.syg.dataource.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.DefaultTransactionStatus;

import javax.sql.DataSource;

/**
 * @author syg
 */
@Slf4j
public class SygDataSourceTransactionManager extends DataSourceTransactionManager {

    private static final long serialVersionUID = -3121954027178566576L;

    public SygDataSourceTransactionManager() {
        setNestedTransactionAllowed(true);
    }

    public SygDataSourceTransactionManager(DataSource dataSource) {
        super(dataSource);
    }

    @Override
    protected Object doGetTransaction() {
        Object object = super.doGetTransaction();
        log.info("完成初始化创建工作");
        return object;
    }

    @Override
    protected void doBegin(Object transaction, TransactionDefinition definition) {
        super.doBegin(transaction, definition);
        log.info("开启事务完成");
    }

    @Override
    protected void doCommit(DefaultTransactionStatus status) {
        super.doCommit(status);
        log.info("提交事务完成");
    }

    @Override
    protected void doRollback(DefaultTransactionStatus status) {
        super.doRollback(status);
    }


}
